/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ttt.nor2.db;

import com.ttt.nor2.util.ExceptionUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Hashtable;
import org.apache.log4j.Logger;

/**
 *
 * @author anuphabm
 */
public class HtbClassAlarm {

    private Logger logger = Logger.getLogger(HtbClassAlarm.class);
    private Connection conn;

    public HtbClassAlarm(Connection conn) {
        this.conn = conn;
        logger.debug("Start class HtbClassAlart");
    }

    public Hashtable loadData() {
        Hashtable htb = new Hashtable();
        String sql = "select * from class_alarm where flag_working='Y'";
        try {
            PreparedStatement pstmt = conn.prepareStatement(sql);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                ClassAlarm c = new ClassAlarm();
                c.setClassid(rs.getInt("class_id"));
                c.setClassName(rs.getString("class_name"));
                htb.put(rs.getString("bit"), c);
            }
            rs.close();
            pstmt.close();
            rs = null;
            pstmt = null;

        } catch (Exception e) {
            logger.error("Exception load class name " + ExceptionUtil.getStackTrace(e));
        } finally {
            /*
            try {
                conn.close();
            } catch (SQLException ex) {
                logger.error("Exception close connection error " + ExceptionUtil.getStackTrace(ex));
            }
            */

        }
        return htb;
    }
}
